<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .sliderbar {
            position: fixed;
            right: 0;
            bottom: 100px;
            width: 40px;
            height: 40px;
            text-align: center;
            line-height: 40px;
            cursor: pointer;
            color: #fff;
        }
        
        .con {
            position: absolute;
            left: 0;
            top: 0;
            width: 200px;
            height: 40px;
            background-color: purple;
            z-index: -1;
        }
    </style>
    <!-- <script src="js/animate.js"></script> -->
</head>

<body>
    <div class="sliderbar">
        <span>←</span>
        <div class="con">问题反馈</div>
    </div>
    <script>
        // 获取元素
        var span = document.querySelector('span');
        var con = document.querySelector('.con');
        var sliderbar = document.querySelector('.sliderbar');
        sliderbar.addEventListener('mouseover', function() {
            animate(con, -160, function() {
                span.innerHTML = '→';
            });
        })
        sliderbar.addEventListener('mouseout', function() {
            animate(con, 0, function() {
                span.innerHTML = '←';
            })
        })
        //  动画函数的封装
        function animate(obj, target, callback) {
            clearInterval(obj.timer)
            obj.timer = setInterval(function() {
                    // 计算步长值
                var step = (target - obj.offsetLeft) / 10;
                step = step > 0 ? Math.ceil(step) : Math.floor(step)
                if (target === obj.offsetLeft) {
                    clearInterval(obj.timer)
                    callback && callback()
                }
                obj.style.left = obj.offsetLeft + step + 'px'

            }, 10)
        }
    </script>
</body>

</html>